package vip.xiaonuo.smzq.modular.kcl.controller;

import javax.annotation.Resource;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import vip.xiaonuo.smzq.modular.kcl.entity.Zycl;
import vip.xiaonuo.smzq.modular.kcl.entity.vo.ReservesEdit;
import vip.xiaonuo.smzq.modular.kcl.entity.vo.ResourceReserves;
import vip.xiaonuo.smzq.modular.kcl.service.IZyclService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import vip.xiaonuo.common.pojo.CommonResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


/**
 * 资源储量
 *
 * @author eomer
 * @since 2024-02-22
 */
@Api(tags = "资源储量")
@RestController
@RequestMapping("/kcl/zycl")
@Validated
public class ZyclController {

    @Resource
    private IZyclService iZyclService;

    /**
     * 添加资源储量
     */
    @ApiOperation("添加资源储量")
    @PostMapping("/add")
    public CommonResult<String> add(@RequestBody @Valid Zycl zycl) {
        iZyclService.save(zycl);
        return CommonResult.ok();
    }

    /**
     * 批量添加资源储量
     */
    @ApiOperation("批量添加资源储量")
    @PostMapping("/addList")
    public CommonResult<String> addList(@RequestBody @Valid List<Zycl> zycls) {
        Integer i = iZyclService.addList(zycls);
        return CommonResult.ok();
    }

    /**
     * 删除资源储量
     */
    @ApiOperation("删除资源储量")
    @PostMapping("/delete")
    public CommonResult<String> delete(@ApiParam(name = "pkid", value = "主键") @RequestParam String pkid) {
        iZyclService.removeById(pkid);
        return CommonResult.ok();
    }

    /**
     * 编辑资源储量
     */
    @ApiOperation("编辑资源储量")
    @PostMapping("/edit")
    public CommonResult<String> edit(@RequestBody @Valid Zycl zycl) {
        iZyclService.updateById(zycl);
        return CommonResult.ok();
    }


    /**
     * 资源储量列表查询
     */
    @ApiOperation("资源储量列表查询")
    @GetMapping("/getResourceReservesList")
    public CommonResult<List<ResourceReserves>> getResourceReservesList(
            @ApiParam(name = "kqbm", value = "矿区编码", required = true) @RequestParam String kqbm,
            @ApiParam(name = "djflbm", value = "登记分类编码", required = true) @RequestParam Integer djflbm,
            @ApiParam(name = "nd", value = "年度", required = true) @RequestParam Integer nd
    ) {
        return CommonResult.data(iZyclService.getResourceReservesList(kqbm, djflbm, nd));
    }

    /**
     * 资源储量填报编辑列表查询
     */
    @ApiOperation("资源储量填报编辑列表查询")
    @GetMapping("/getReservesEditList")
    public CommonResult<List<ReservesEdit>> getReservesEditList(
            @ApiParam(name = "kqbm", value = "矿区编码", required = true) @RequestParam String kqbm,
            @ApiParam(name = "djflbm", value = "登记分类编码", required = true) @RequestParam Integer djflbm,
            @ApiParam(name = "nd", value = "年度", required = true) @RequestParam Integer nd
    ) {
        return CommonResult.data(iZyclService.getReservesEditList(kqbm, djflbm, nd));
    }


    /**
     * 添加资源储量及其相关
     */
    @ApiOperation("添加资源储量及其相关")
    @PostMapping("/addReserves")
    public CommonResult<String> add(@RequestBody @Valid List<ReservesEdit> reservesList) {
        String result = iZyclService.addReserves(reservesList);
        return CommonResult.ok(result);
    }


    /**
     * 同矿年度下拉框
     */
    @ApiOperation("同矿年度下拉框")
    @GetMapping("/getNdList")
    public CommonResult<List<Integer>> getNdList(
            @ApiParam(name = "kqbm", value = "矿区编码", required = true) @RequestParam String kqbm,
            @ApiParam(name = "djflbm", value = "登记分类编码", required = true) @RequestParam Integer djflbm
    ) {
        return CommonResult.data(iZyclService.getNdList(kqbm, djflbm));
    }

    /**
     * 资源储量分页查询
     */
    @ApiOperation("资源储量分页查询")
    @GetMapping("/list")
    public CommonResult<Page<Zycl>> page() {
        return CommonResult.data(iZyclService.page(new Zycl()));
    }
}
